create-protocol-parameters-update: validate cost models' size#1012
create-protocol-parameters-update: validate cost models' size#1012
Conversation
| Just (model :: L.CostModel) -> do | ||
| let actual = Map.size (L.costModelToMap model) | ||
| expected = languageToParameterCount lang | ||
| unless (expected == actual) $ throwE $ CostModelsErrorWrongSize expected actual | ||
| return () |
Check warning
Code scanning / HLint
Redundant return Warning
| hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size = | ||
| propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
| -- This file has 184 entries, whereas PV1 requires 166 | ||
| -- TODO @smelc this test does not pass: the command succeeds, whereas it should fail! |
There was a problem hiding this comment.
My guess is that for PV1 the ledger deserialization fixes the problem by filling in missing parameters. Investigating. (this could also be an issue if the ledger is automatically trimming extra parameters, I need to check that too).
There was a problem hiding this comment.
Yes, it's something along those lines. The defaulting logic may also change depending whether the cost model is an array or a map. 🫠
ledger is automatically trimming extra parameters
I think it is not, we're only doing trimming in alonzo genesis reading, because the node didn't want to start in some cases.
| L.PlutusV2 -> | ||
| let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 | ||
| caseShelleyToBabbageOrConwayEraOnwards | ||
| (const $ nbParamNames - 10) -- Ten parameters were added to V2 in Conway, need to remove them here |
There was a problem hiding this comment.
I'm not so sure about hardcoding that number 10. We should account for the fact that the number of params can change in the future, however it's unlikely. That's why there's jumping over many hoops in Cardano.Api.Genesis and Test.Cardano.Api.Genesis, so we will get a clear signal when things unexpectedly change.
| return costModels | ||
| where | ||
| checkCostModelSize :: L.CostModels -> L.Language -> ExceptT CostModelsError IO () | ||
| checkCostModelSize models lang = |
There was a problem hiding this comment.
I think those checks should be in cardano-api so we can reuse them in decoding genesis as well, because genesis can contain PV2 and PV3 models. This is used only in starting testnets afaik.
| hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size = | ||
| propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
| -- This file has 184 entries, whereas PV1 requires 166 | ||
| -- TODO @smelc this test does not pass: the command succeeds, whereas it should fail! |
There was a problem hiding this comment.
Yes, it's something along those lines. The defaulting logic may also change depending whether the cost model is an array or a map. 🫠
ledger is automatically trimming extra parameters
I think it is not, we're only doing trimming in alonzo genesis reading, because the node didn't want to start in some cases.
| languageToParameterCount = \case | ||
| L.PlutusV1 -> length $ allValues @PlutusV1.ParamName -- 166 | ||
| L.PlutusV2 -> | ||
| let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 |
There was a problem hiding this comment.
| let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 | |
| let nParamNames = length $ allValues @PlutusV2.ParamName in -- 185 |
😄
ad333c5 to
20fee47
Compare
20fee47 to
a2ce41c
Compare
|
This PR is stale because it has been open 45 days with no activity. |
|
To be resumed after IntersectMBO/cardano-api#729 is merged |
|
This PR is stale because it has been open 45 days with no activity. |
|
This PR is stale because it has been open 45 days with no activity. |
|
This PR is stale because it has been open 45 days with no activity. |
|
This PR is stale because it has been open 45 days with no activity. |
|
This PR is stale because it has been open 45 days with no activity. |
Changelog
Context
Fixes #928
How to trust this PR
Checklist